'use strict';

module.exports = {
  async up(queryInterface, Sequelize) {
    await queryInterface.createTable('users', {
      id: {
        allowNull: false,
        autoIncrement: true,
        primaryKey: true,
        type: Sequelize.INTEGER.UNSIGNED,
      },
      avatar: {
        type: Sequelize.STRING(255), // 存储头像 URL 或路径
        allowNull: true,
      },
      sex: {
        type: Sequelize.ENUM('male', 'female', 'other'), // 可选性别枚举
        allowNull: true,
      },
      introduce: {
        type: Sequelize.TEXT, // 用户介绍
        allowNull: true,
      },
      username: {
        type: Sequelize.STRING(100),
        allowNull: false,
        unique: true, // 用户名唯一
      },
      phone: {
        type: Sequelize.STRING(20),
        allowNull: true,
        unique: true, // 手机号唯一
      },
      email: {
        type: Sequelize.STRING(100),
        allowNull: false,
        unique: true, // 邮箱唯一
      },
      password: {
        type: Sequelize.CHAR(64), // 密码哈希值
        allowNull: false,
      },
      created_at: {
        allowNull: false,
        type: Sequelize.DATE,
        defaultValue: Sequelize.literal('CURRENT_TIMESTAMP'),
      },
      updated_at: {
        allowNull: false,
        type: Sequelize.DATE,
        defaultValue: Sequelize.literal('CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP'),
      },
    });
  },

  async down(queryInterface, Sequelize) {
    await queryInterface.dropTable('users');
  }
};